{% extends 'eventyay_common/base.html' %}
{% load i18n %}
{% load bootstrap3 %}
{% block title %}{{ _('Notification settings') }}{% endblock %}

{% block nav_top_header %}
    <a href='{% url "eventyay_common:account" %}' class='dropdown-toggle'>
        <span class='fa-stack fa-lg'>
            <i class='fa fa-circle fa-stack-2x'></i>
            <i class='fa fa-user fa-stack-1x fa-inverse'></i>
        </span>
        <div class='context-indicator'>
            <span class='context-name'>{{ _('Account') }}</span>
        </div>
    </a>
{% endblock nav_top_header %}

{% block content %}
    <h1>{{ _('Notification settings') }}</h1>
    <form method='post'>
        {% csrf_token %}
        <fieldset>
            {% if request.user.notifications_send %}
                <div class='alert alert-info'>
                    <button name='notifications_send' value='off' type='submit' class='pull-right flip btn btn-default'>
                        <span class='fa fa-bell-slash'></span>
                        {{ _('Disable') }}
                    </button>
                    {{ _('Notifications are turned on according to the settings below.') }}
                    <div class='clearfix'></div>
                </div>
            {% else %}
                <div class='alert alert-warning'>
                    <button name='notifications_send' value='on' type='submit' class='pull-right flip btn btn-default'>
                        <span class='fa fa-bell'></span>
                        {{ _('Enable') }}
                    </button>
                    {{ _('All notifications are turned off globally.') }}
                    <div class='clearfix'></div>
                </div>
            {% endif %}
        </fieldset>
    </form>
    <form class='form-inline' method='get'>
        <fieldset>
            <legend>{{ _('Choose event') }}</legend>
            <p>
                <select name='event' class='form-control simple-subevent-choice'
                    data-model-select2="event"
                    data-placeholder="{{ _('All my events') }}"
                    data-select2-url="{% url 'control:events.typeahead' %}">
                    {% if event %}
                        <option value="{{ event.pk }}" selected>
                            {{ event.name }}
                        </option>
                    {% endif %}
                </select>
                <span class='help-block'>{{ _('Save your modifications before switching events.') }}</span>
            </p>
        </fieldset>
    </form>
    <form method='post'>
        {% csrf_token %}
        <fieldset>
            <legend>{{ _('Choose notifications to get') }}</legend>
            <table class='table'>
                <thead>
                <tr>
                    <th>{{ _('Notification type') }}</th>
                    <th class='text-center'>{{ _('E-Mail notification') }}</th>
                </tr>
                </thead>
                <tbody>
                {% for type, enabled, global in types %}
                    <tr>
                        <td>
                            {{ type.verbose_name }}
                        </td>
                        <td class='text-center'>
                            {% if not event or type.required_permission in permset %}
                                <select name='mail:{{ type.action_type }}' class='form-control'>
                                    {% if event %}
                                        <option value='global'>{{ _('Global') }} ({% if global.mail %}{{ _('On') }}{% else %}{{ _('Off') }}{% endif %})</option>{% endif %}
                                    <option value='off' {% if "mail" in enabled and enabled.mail == False %}selected{% endif %}>{{ _('Off') }}</option>
                                    <option value='on' {% if enabled.mail %}selected{% endif %}>{{ _('On') }}</option>
                                </select>
                            {% else %}
                                <span class='fa fa-lock' data-toggle='tooltip' title="{{ _('You have no permission to receive this notification') }}"></span>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </fieldset>
        <div class='form-group submit-group'>
            <button type='submit' class='btn btn-primary btn-save'>
                {{ _('Save') }}
            </button>
        </div>
    </form>
{% endblock content %}
